/*    */ package server.shops;
/*    */ 
/*    */ import java.util.concurrent.ArrayBlockingQueue;
/*    */ import java.util.concurrent.atomic.AtomicInteger;
/*    */ import java.util.logging.Level;
/*    */ import java.util.logging.Logger;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class HiredMerchantSave
/*    */ {
/*    */   public static final int NumSavingThreads = 5;
/* 18 */   private static final TimingThread[] Threads = new TimingThread[5];
/* 19 */   private static final AtomicInteger Distribute = new AtomicInteger(0);
/*    */   
/*    */   static {
/* 22 */     for (int i = 0; i < Threads.length; i++) {
/* 23 */       Threads[i] = new TimingThread(new HiredMerchantSaveRunnable());
/*    */     }
/*    */   }
/*    */   
/*    */   public static void QueueShopForSave(HiredMerchant hm) {
/* 28 */     int Current = Distribute.getAndIncrement() % 5;
/* 29 */     Threads[Current].getRunnable().Queue(hm);
/*    */   }
/*    */   
/*    */   public static void Execute(Object ToNotify) {
/* 33 */     for (TimingThread Thread1 : Threads) {
/* 34 */       Thread1.getRunnable().SetToNotify(ToNotify);
/*    */     }
/* 36 */     for (TimingThread Thread : Threads)
/* 37 */       Thread.start(); 
/*    */   }
/*    */   
/*    */   private static class HiredMerchantSaveRunnable
/*    */     implements Runnable
/*    */   {
/* 43 */     private static final AtomicInteger RunningThreadID = new AtomicInteger(0);
/* 44 */     private final int ThreadID = RunningThreadID.incrementAndGet();
/* 45 */     private final ArrayBlockingQueue<HiredMerchant> Queue = new ArrayBlockingQueue<>(500);
/* 46 */     private long TimeTaken = 0L;
/* 47 */     private int ShopsSaved = 0;
/*    */     
/*    */     private Object ToNotify;
/*    */     
/*    */     public void run() {
/*    */       try {
/* 53 */         while (!this.Queue.isEmpty()) {
/* 54 */           HiredMerchant next = this.Queue.take();
/* 55 */           long Start = System.currentTimeMillis();
/* 56 */           if (next.getMCOwner() != null && next.getMCOwner().getPlayerShop() == next) {
/* 57 */             next.getMCOwner().setPlayerShop(null);
/*    */           }
/* 59 */           next.closeShop(true, false);
/* 60 */           this.TimeTaken += System.currentTimeMillis() - Start;
/* 61 */           this.ShopsSaved++;
/*    */         } 
/* 63 */         System.out.println("[保存雇佣商店数据 线程 " + this.ThreadID + "] 共保存: " + this.ShopsSaved + " | 耗时: " + this.TimeTaken + " 毫秒.");
/* 64 */         synchronized (this.ToNotify) {
/* 65 */           this.ToNotify.notify();
/*    */         } 
/* 67 */       } catch (InterruptedException ex) {
/* 68 */         Logger.getLogger(HiredMerchantSave.class.getName()).log(Level.SEVERE, (String)null, ex);
/*    */       } 
/*    */     }
/*    */     
/*    */     private void Queue(HiredMerchant hm) {
/* 73 */       this.Queue.add(hm);
/*    */     }
/*    */     
/*    */     private void SetToNotify(Object o) {
/* 77 */       if (this.ToNotify == null)
/* 78 */         this.ToNotify = o; 
/*    */     }
/*    */     
/*    */     private HiredMerchantSaveRunnable() {}
/*    */   }
/*    */   
/*    */   private static class TimingThread extends Thread {
/*    */     private final HiredMerchantSave.HiredMerchantSaveRunnable ext;
/*    */     
/*    */     public TimingThread(HiredMerchantSave.HiredMerchantSaveRunnable r) {
/* 88 */       super(r);
/* 89 */       this.ext = r;
/*    */     }
/*    */     
/*    */     public HiredMerchantSave.HiredMerchantSaveRunnable getRunnable() {
/* 93 */       return this.ext;
/*    */     }
/*    */   }
/*    */ }


/* Location:              C:\PGX\Server.jar!\server\shops\HiredMerchantSave.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */